package com.xl98.service.impl;

import com.xl98.entity.Role;

import com.xl98.entity.UserRole;
import com.xl98.mapper.RoleMapper;
import com.xl98.mapper.UserRoleMapper;
import com.xl98.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ls
 * @since 2020-05-15
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Autowired
    private UserRoleMapper userRoleMapper;
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public List<Role> selectRoleByUserId(String uid) {
        HashMap<String, Object> map = new HashMap<>();
        List roles = new ArrayList();
        map.put("user_id",uid);
        List<UserRole> userRoles = userRoleMapper.selectByMap(map);
        for (UserRole userRole : userRoles) {
            roles.add(roleMapper.selectById(userRole.getRoleId()));
        }
        return roles;
    }

    @Override
    public List<Role> selectAllRole() {
        return roleMapper.selectList(null);
    }
}
